﻿<Serializable()>
Public Class MilestoneEditor
    Private LinkedMilestoneValue As L3DObjectsLibrary.Milestone
    Public Event CloseRequest(ByVal sender As Object, ByVal CloseStatus As Microsoft.VisualBasic.MsgBoxResult)
    Public Property LinkedMilestone As L3DObjectsLibrary.Milestone
        Get
            Return LinkedMilestoneValue
        End Get
        Set(ByVal value As L3DObjectsLibrary.Milestone)
            LinkedMilestoneValue = value
            FillFromLinkedMilestone()
        End Set
    End Property
    Private Sub FillFromLinkedMilestone()
        txtName.Text = LinkedMilestone.Name
        txtRemark.Text = LinkedMilestone.Remark
        dateMilestoneDate.Value = LinkedMilestone.MilestoneDate
        dateMilestoneRealDate.Value = LinkedMilestone.MilestoneRealDate
        txtName.Focus()
        txtName.SelectAll()
    End Sub
    Private Sub ControlsHandlersAdd(ByVal Father As Object)
        For Each Control As Windows.Forms.Control In Father.Controls
            If Control.HasChildren = True Then
                ControlsHandlersAdd(Control)
            End If
            If Control.GetType = GetType(Windows.Forms.TextBox) _
                    Or Control.GetType = GetType(Windows.Forms.DateTimePicker) _
                    Or Control.GetType = GetType(Windows.Forms.ComboBox) _
                    Or Control.GetType = GetType(Windows.Forms.NumericUpDown) _
                    Or Control.GetType = GetType(Windows.Forms.CheckBox) Then
                AddHandler Control.KeyUp, AddressOf Key_UP
            End If
        Next
    End Sub
    Private Sub Key_UP(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Windows.Forms.Keys.Enter Then
            cmdOK.PerformClick()
        ElseIf e.KeyCode = Windows.Forms.Keys.Escape Then
            cmdCancel.PerformClick()
        End If
    End Sub
    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        RaiseEvent CloseRequest(Me, MsgBoxResult.Ok)
        LinkedMilestone.Name = txtName.Text
        LinkedMilestone.Remark = txtRemark.Text
        LinkedMilestone.MilestoneDate = dateMilestoneDate.Value
        LinkedMilestone.MilestoneRealDate = dateMilestoneRealDate.Value
    End Sub
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        RaiseEvent CloseRequest(Me, MsgBoxResult.Cancel)
    End Sub
    Private Sub MilestoneEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ControlsHandlersAdd(Me)
    End Sub
    Private Sub MilestoneEditor_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As System.Drawing.Graphics = e.Graphics
        Dim Rect As New System.Drawing.Rectangle(1, 1, Me.Width - 3, Me.Height - 3)
        Dim MyPen As New System.Drawing.Pen(New System.Drawing.SolidBrush(Drawing.ColorTranslator.FromHtml("#000000")), 1)
        g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
        VMGenLibrary.Graphics.DrawRoundedRectangle(g, MyPen, Rect, New System.Drawing.Size(20, 20), Drawing.ColorTranslator.FromHtml("#FFFFC0"))

    End Sub

    Private Sub cmdUpDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click, cmdDown.Click
        If sender Is cmdUp Then
            dateMilestoneDate.Value = dateMilestoneRealDate.Value
        ElseIf sender Is cmdDown Then
            dateMilestoneRealDate.Value = dateMilestoneDate.Value
        End If
    End Sub
End Class
